
#define BOOST_TEST_MAIN
//#define BOOST_TEST_MODULE tcp_data_handler

#include <boost/test/included/unit_test.hpp>

#include "tcp_data_handler.h"

using namespace kingnet ;


class test_connection : public tcp_data_handler
{
public:
    virtual ~test_connection() {fini();} ;
protected:
    void on_connected()
    {
        printf("on_connected\n") ;
    }

    void on_closed(int error_type,int error_no)
    {
        printf("on_closed:%d %d\n",error_type,error_no) ;

    }

    int get_packet_info(const char* data,int size,packet_info* pi)
    {
        return 0 ;
    }

    int process_packet(const packet_info* pi)
    {
        return 0 ;
    }

} ;

BOOST_AUTO_TEST_SUITE(tcp_data_handler) ;


BOOST_AUTO_TEST_CASE(connect)
{

    using kingnet::tcp_data_handler ;
    test_connection conn ;
    epoll_reactor engine ;
    BOOST_REQUIRE(engine.init(1000)==0) ;
    BOOST_REQUIRE(conn.init(&engine,"127.0.0.1",9999)==0) ;
    BOOST_CHECK(conn.get_status() == tcp_data_handler::STATUS_CONNECTING) ;
    engine.run_once(1000) ;
    engine.run_once(1000) ;
    engine.run_once(1000) ;
    engine.run_once(1000) ;
    BOOST_CHECK(conn.get_status() == tcp_data_handler::STATUS_CONNECTED) ;


}

BOOST_AUTO_TEST_SUITE_END() ;

